#include"mystring.h"
#include<string>
#include<stdio.h>
void teststr1()
{

    xyx::string str1("hello world");
    cout << str1.c_str() << endl;
    
    for(size_t i = 0; i < str1.size(); ++i)
    {
        cout << str1[i]; 
    }
    cout << endl;
    
    xyx::string:: iterator it = str1.begin();
    
    while(it != str1.end())
    {
        *it += 1;
        cout << *it;
        it++;
    }
    cout << endl;

    for(auto e : str1)
    {
        cout << e;
    }
    cout << endl;

}

void teststr2()
{
    //xyx::string str1("hello");
    //cout << str1.capacity() << endl;
    //    
    //    str1.reserve(100);
    //
    //    cout << str1.capacity() << endl;
    

    xyx::string str1("hello");
    str1.push_back(' ');
    str1.push_back('#');

    str1.append("world");

    cout << str1.c_str() << endl;
    cout << str1.capacity() << endl;

    xyx::string str2;
    str2 += "xxxxx";
    str2 += ' ';
    str2 += "ready to dorm";

    cout << str2.c_str() << endl;

}

void teststr3()
{
    xyx::string str("hello");
    
    str.insert(0,3,'~');

    cout << str.c_str() << endl;
    
    str.insert(0,"nihao ");

    cout << str.c_str() << endl;

    str.erase(3,3);
    cout << str.c_str() << endl;

    
    str.erase(7, 20);
    cout << str.c_str() << endl;
    
    str.erase(2);
    cout << str.c_str() << endl;

}

void teststr4()
{
//    xyx::string s("hello world");
//    
//    size_t pos1 = s.find(' ');
//    cout << pos1 << endl;
//
//    cout << s.find("wo");
//
    xyx::string s("hell world");
    cout <<  s << endl;

    xyx::string s1 =s;

    cout << s1<< endl;

}

void teststr5()
{
 //   xyx::string s("hello world");
 //   cout << s.c_str() << endl;

 //   s.resize(6);
 //   cout << s << endl;
 //   s.resize(12,'x');
 //   cout << s << endl;
 //   s.resize(20,'y');
 //   cout << s << endl;
    
    // string s1;
//    cin >> s1;
//
//    cout << s1 << endl;

    
    xyx::string s1("hello world");
    xyx::string s2("hello worldxxx");

    cout << (s1 < s2) << endl;
    cout << (s1 <= s2) << endl;
    cout << (s1 > s2) << endl;
    cout << (s1 >= s2) << endl;
    cout << (s1 == s2) << endl;
    cout << (s1 != s2) << endl;


}

void teststr6()
{
    xyx::string s1("hello world");
    xyx::string s2 = s1;
    cout << s2 << endl;
   
    //写时拷贝验证
    //std::string s1("hello world");
    //std::string s2(s1);
    //printf("%p\n",s1.c_str());
    //printf("%p\n",s2.c_str());

    //s2[0] = 'x';

    //printf("%p\n",s-1.c_str());
    //printf("%p\n",s2.c_str());

    
}

int main()
{
    //teststr1();
    //teststr2();
    //teststr3();
    //teststr4();
    //teststr5();
    teststr6();
    return 0;
}
